<?php
/*
 * chech if the user exist 
 * if exist add user to sesson var
 * if not go to the register page
 */
class Login_Model extends Model {
    
	public function __construct() {
		parent::__construct();
                echo $_SESSION['flag'];
	}

	public function game() {
		$sth = $this->db->prepare("SELECT id FROM users WHERE 
				login = :login AND password = MD5(:password)");
		$sth->execute(array(
			':login' => $_POST['login'],
			':password' => $_POST['password']
		));
		
	 
		
		$count =  $sth->rowCount();
		if ($count > 0) {
			// login
			Session::init();
			Session::set('loggedIn', true);
                        $_SESSION['username'] = $_POST['login'];
                        $_SESSION['fenrty']=0;
			header('location: ../game');
		} else {
                    // need validaet the password !
                    //if the same user and diff password 
                    //user will still in the same page
                    //we need provide the help with password
			header('location: ../lognew');
                        
		}
		
	}
	
}